package cn.baiweigang.uu.task;

import cn.baiweigang.uu.constants.BtcConfig;
import cn.baiweigang.uu.model.AccountInfo;
import cn.baiweigang.uu.service.linearswap.AccountService;
import cn.baiweigang.uu.service.DbService;
import cn.baiweigang.uu.utils.LogUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@Configuration
@EnableScheduling
@EnableAsync
public class SummaryTask {

    @Autowired
    private DbService dbService;
    @Autowired
    private AccountService accountService;

    @Scheduled(cron = "00 59 23 * * ?")
    private void day1Order() {
        try {
            AccountInfo accountInfo = accountService.queryFromDb(BtcConfig.ACCOUNT_NAME);
            accountService.updateAccountFromHB(accountInfo);
            LogUtil.logInfo("23:59:00汇总当天信息 " + accountInfo.getAccountName());
            //汇总订单信息
            dbService.insertSummarySheetForDay1(accountInfo);
            //汇总账户余额信息
            dbService.insertBalanceHistoryForDay1(accountInfo);
        } catch (Throwable e) {
            LogUtil.logError("按天汇总任务执行异常 " + e.getMessage());
        }
    }
}
